package com.hgy.chapter3.service;

import java.util.List;
import java.util.Map;

import com.hgy.chapter3.dao.BaseDao;
import com.hgy.chapter3.model.Customer;
import com.hgy.framework.annotation.Service;
import com.hgy.framework.annotation.Transaction;
import com.hgy.framework.bean.FileParam;
import com.hgy.framework.helper.UploadHelper;

@Service
public class CustomerService {
	
	
	@Transaction
	public List<Customer> getCustomerList() {
		String sql = "SELECT * FROM tb_customer";
		return BaseDao.queryEntityList(Customer.class, sql);
	}

	@Transaction
	public Customer getCustomer(Long id) {
		String sql = "SELECT * FROM tb_customer WHERE id = ?";
		return BaseDao.queryEntity(Customer.class, sql, id);
	}

	@Transaction
	public boolean createCustomer(Map<String, Object> fieldMap , FileParam fileParam) {
		boolean result = BaseDao.insertEntity(fieldMap);
		if(result){
			UploadHelper.uploadFile("/tmp/upload/", fileParam);
		}
		return result;
	}

	@Transaction
	public boolean updateCustomer(Long id, Map<String, Object> fieldMap) {
		return BaseDao.updateEntity(id, fieldMap);
	}

	@Transaction
	public boolean deleteCustomer(Long id) {
		return BaseDao.deleteEntity(id);
	}

}
